import os
import re
import threading
import pandas as pd
import numpy as np
import time
from commen.log import Logger
import openpyxl
import datetime
import commen.config


def ImuDatacontinuity():
    # ---------读取config文件获取筛选字段内容--------------------------
    caninskey = commen.config.global_config.getRaw('keywords', 'cankeyins')

    # ---------读取config文件获取筛选字段内容--------------------------
    logger = Logger(logger='TestMylog').getlog()
    # -----------------------创建excel--------------------------------------------
    # 获取当前时间
    time_now = time.strftime("%Y%m%d-%H%M", time.localtime())
    # 获取当前路径
    result_root = os.getcwd()
    root = os.getcwd()
    result_path = result_root + r'\result' + "\\" + time_now
    log_path = root + r'\original-logfile' + '\\'
    # -----遍历对比log路径获取要对比的文件名路径信息----------------------
    for root, dirs, files in os.walk(log_path):
        for file in files:
            # if "Data" in file:
            #     aa = os.path.join(root, file)
            # if "can" in file:
            #     bb = os.path.join(root, file)
            if "can" in file:

                bb = os.path.join(root, file)
    canfile = open(bb, 'r', encoding='gbk')  # 打开can.log目标文件
    logger.info("打开目标文件")
    canlines = canfile.readlines()
    savelog = result_path + "can发RTK.log"
    book = open(savelog, 'w', encoding='gbk')  # 打开一个将写的文件
    for canline in canlines:
        if "80              Tx" in canline:

            log1 = canline[:canline.index("Length")]

            caninsdatamessage = log1.split("Tx   d 8")
            message = caninsdatamessage[1].replace(" ","")
            messag = message + '\n'
            book.writelines(messag)



















ImuDatacontinuity()